package org.vse.aha.gui.actions;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.Lookup;
import org.openide.util.NbBundle.Messages;
import org.vse.aha.common.quotes.IQuotesProvider;
import org.vse.aha.common.quotes.Quote;

@ActionID(category = "Tools",
id = "org.vse.aha.gui.actions.QuotesToConsole")
@ActionRegistration(
    iconBase = "org/vse/aha/gui/actions/quotesToConsoleIcon16.png",
    displayName = "#CTL_QuotesToConsole")
@ActionReferences({
  @ActionReference(path = "Menu/Tools", position = -100),
  @ActionReference(path = "Toolbars/File", position = 500)
})
@Messages("CTL_QuotesToConsole=Výroky do konzole")
public final class QuotesToConsole implements ActionListener {

  @Override
  public void actionPerformed(ActionEvent e) {
    Collection<? extends IQuotesProvider> pvc = Lookup.getDefault().lookupAll(IQuotesProvider.class);
    ArrayList<Quote> výroky = new ArrayList<>();
    for (IQuotesProvider pv : pvc) {
      výroky.addAll(pv.getVýroky());
    }

    for (Quote v : výroky) {
      System.out.println(v.getAutor() + ": " + v.getTextVýroku());
    }
  }
}
